/*
 * Sphere.java
 */

package com.math3d;

import javax.media.j3d.Appearance;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.GraphicsContext3D;
import javax.media.j3d.TransparencyAttributes;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;

import com.game.obj.GameObject;
import com.render3d.ms3d.Model3D;
import com.sun.j3d.utils.geometry.Sphere;


/**
 *
 * @author  Norbert Nopper
 */
public class DisplayBoundingSphere extends Model3D {
    
    /**
     * Class variable for the red color.
     */
    final public static Color3f RED = new Color3f(1.0f, 0.0f, 0.0f);
    
    /**
     * Class variable for the green color.
     */
    final public static Color3f GREEN = new Color3f(0.0f, 1.0f, 0.0f);

    /**
     * Class variable for the blue color.
     */
    final public static Color3f BLUE = new Color3f(0.0f, 0.0f, 1.0f);
    
    final public static int MODEL_FASTEST = 0;
    final public static int MODEL_NICEST = 1;
    final public static int MODEL_SHADE_FLAT = 2;
    final public static int MODEL_SHADE_GOURAUD = 3;
        
    final public static int TRANS_NONE = 0;
    final public static int TRANS_FASTEST = 1;
    final public static int TRANS_NICEST = 2;
    final public static int TRANS_SCREEN_DOOR = 3;
    final public static int TRANS_BLENDED = 4;    
    
    private Sphere      sphere;
    
    public DisplayBoundingSphere(BoundingSphere boundingSphere) {
        Point3d center = new Point3d();
        boundingSphere.getCenter(center);
        
        Appearance appearance = new Appearance();
        appearance.setColoringAttributes(new ColoringAttributes(GREEN, MODEL_FASTEST));
        appearance.setTransparencyAttributes(new TransparencyAttributes(TRANS_FASTEST, 0.9f));

        sphere = new Sphere((float)boundingSphere.getRadius(), appearance);
                
        x = center.x;
        y = center.y;
        z = center.z;
    }
        
    public void changeColor(Color3f color) {
        Appearance appearance = sphere.getAppearance();
        ColoringAttributes attributes = appearance.getColoringAttributes();
        attributes.setColor(color);
        appearance.setColoringAttributes(attributes);
        sphere.setAppearance(appearance);
    }
        
    /**
     * Nothing needs to be updated.
     *
     * @param time the passed time in milliseconds
     */
    protected void updateModel(Transform3d camera, GameObject player, long exTime) {
        // do nothing
    }
    
    /**
     * Render the line.
     *
     * @param gc3D the graphics contect 3D to render on
     */    
    protected void drawModel(GraphicsContext3D gc3D) {        
        gc3D.setAppearance(sphere.getAppearance());
        
        gc3D.draw(sphere.getShape());        
    }
    
}
